home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / scripts / resolution_test < prev    next >
Encoding:
Text File  |  2009-04-27  |  1.2 KB  |  56 lines

  1. #!/usr/bin/python
  2.  
  3. import os
  4. import re
  5. import sys
  6.  
  7.  
  8. def error(message):
  9.     sys.stderr.write("ERROR: %s\n" % message)
  10.     sys.exit(1)
  11.  
  12. def check_ati():
  13.     command = "lsmod | grep fglrx"
  14.     fglrx_lines = os.popen(command).readlines()
  15.     if len(fglrx_lines) != 0:
  16.         print "impossible with fglrx"
  17.         return True
  18.  
  19.     return False
  20.  
  21. def check_resolution():
  22.     if check_ati():
  23.         return True
  24.  
  25.     command = "xrandr -q"
  26.     xrandr_lines = os.popen(command).readlines()
  27.     star_lines = [l for l in xrandr_lines if "*" in l]
  28.     if len(star_lines) != 1:
  29.         error("%s should return a single line with '*'" % command)
  30.  
  31.     star_line = star_lines[0]
  32.     match = re.search(r"(\d+)\s?x\s?(\d+)", star_line)
  33.     if not match:
  34.         error("%s should return pixels like '1024 x 768'" % command)
  35.  
  36.     horizontal = match.group(1)
  37.     vertical = match.group(2)
  38.  
  39.     fields = re.split(r"\s+", star_line)
  40.     star_fields = [f for f in fields if "*" in f]
  41.     if len(star_fields) < 1:
  42.         error("%s should return a refresh rate with '*'" % command)
  43.  
  44.     print "%s x %s" % (horizontal, vertical)
  45.     return True
  46.  
  47. def main(args):
  48.     if check_resolution():
  49.         return 0
  50.  
  51.     return 1
  52.  
  53.  
  54. if __name__ == "__main__":
  55.     sys.exit(main(sys.argv[1:]))
  56.